package com.training.java.core.collections.one;

	import java.util.ArrayList;
	import java.util.HashSet;
	import java.util.Iterator;
	import java.util.LinkedList;
	import java.util.List;
	import java.util.Set;
	import java.util.TreeSet;
	import java.util.LinkedHashSet;


	public class LinkedHashSetDemo {

		public static void main(String[] args) {
			Set<String> students = new LinkedHashSet<String>(); //If you care about the order and LinkedHashSet will maintain the order
			//List list = new LinkedList(); 					//It is slow
			
			
			students.add("Sam");
			students.add("Henry");
			students.add("Almas");
			students.add("vinod");// linked list and array list also accepts duplicates
			students.add("vinod");
			students.add("almas");
			
			//Car focus = new Car("Ford", "Focus", 2014);
			//list.add(focus); // String and objects are not compatible types and therefore
			//will throw an error when system will try to print after Henry
			
			
			//Read from list
			Iterator<String> ite = students.iterator();
			
			while(ite.hasNext()) // read until hasNext value is true
			{
				String studentName = ite.next();
				System.out.println("Student name = " + studentName);
			}
			
			System.out.println("*********************");
			//Read the same list using for each loop
			for(String studentName : students)
			{
				System.out.println("Student name = " + studentName);
			}
		}
		}
